<html>
<head><meta charset="utf-8"><title>git hooks · t-infra · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/index.html">t-infra</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html">git hooks</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="209128244"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209128244" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cass <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209128244">(Sep 04 2020 at 18:46)</a>:</h4>
<p>Hello! Please forgive me if this is an instant "no", as I'm super new to the rust compiler and am not really sure what the standards are regarding what is and isn't considered in-scope. I tried to find the appropriate stream to post this in, so if there's a better one please let me know <span aria-label="heart" class="emoji emoji-2764" role="img" title="heart">:heart:</span></p>
<p>This topic specifically is in regards the use of <a href="https://github.com/rhysd/cargo-husky">cargo-husky</a>, which is a tool I've used in the past with some of my projects, to create a pre-commit git hook that automatically runs <code>./x.py fmt</code>, and maybe also more hooks such as testing or linting.</p>
<p>As recommended in the rustc-dev-guide, I've turned off automatic formatting on save when working on the rust compiler, and instead manually run <code>./x.py fmt</code> before each commit. It would be nice to have this automated via git hooks, and would make for a smoother development experience imo.</p>
<p>Is this something that is worth considering? If not, I understand -- I figured I'd just put this out there in case it was <span aria-label="smiley" class="emoji emoji-1f603" role="img" title="smiley">:smiley:</span> </p>
<p>Thank you for your time!</p>



<a name="209128304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209128304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209128304">(Sep 04 2020 at 18:47)</a>:</h4>
<p>I'd be interested in having pre-written hooks that run <code>x.py test tidy</code>. However I'm strongly against setting up the hooks automatically, it should be opt-in</p>



<a name="209128397"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209128397" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209128397">(Sep 04 2020 at 18:48)</a>:</h4>
<p><span class="user-mention" data-user-id="337739">@Cass</span> I don't think we'd want to tell everyone they <em>should</em> automate it that way, or do it automatically, because many folks do prefer to have more control over when they run things like fmt or tidy. But it'd be perfectly reasonable to have some information that says how to set that up for people who want it, and perhaps have a <code>./x.py install-git-hooks</code> with some options.</p>



<a name="209128730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209128730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cass <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209128730">(Sep 04 2020 at 18:51)</a>:</h4>
<p>that sounds super reasonable -- thanks for the feedback! I'm interested in writing up a PR that includes support for <code>./x.py install-git-hooks &lt;opts&gt;</code> to allow for that, as well as documentation explaining how and why to use it. In particular, what scripts would you recommend including? <code>fmt</code>? <code>tidy</code>?</p>



<a name="209128969"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209128969" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209128969">(Sep 04 2020 at 18:53)</a>:</h4>
<p>I think just <code>tidy</code>, it will run <code>fmt --check</code> automatically</p>



<a name="209129028"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209129028" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209129028">(Sep 04 2020 at 18:54)</a>:</h4>
<p>everything else takes too long to expect people to run it on each commit :/</p>



<a name="209129067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209129067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209129067">(Sep 04 2020 at 18:54)</a>:</h4>
<p><span class="user-mention silent" data-user-id="337739">Cass</span> <a href="#narrow/stream/242791-t-infra/topic/git.20hooks/near/209128730">said</a>:</p>
<blockquote>
<p>that sounds super reasonable -- thanks for the feedback! I'm interested in writing up a PR that includes support for <code>./x.py install-git-hooks &lt;opts&gt;</code> to allow for that, as well as documentation explaining how and why to use it. In particular, what scripts would you recommend including? <code>fmt</code>? <code>tidy</code>?</p>
</blockquote>
<p>take a look at <a href="https://rustc-dev-guide.rust-lang.org/building/bootstrapping.html#contributing-to-bootstrap">https://rustc-dev-guide.rust-lang.org/building/bootstrapping.html#contributing-to-bootstrap</a> for how to add a setting</p>



<a name="209129091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209129091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209129091">(Sep 04 2020 at 18:54)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/blob/master/src/bootstrap/README.md">https://github.com/rust-lang/rust/blob/master/src/bootstrap/README.md</a> has some info too</p>



<a name="209129159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209129159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209129159">(Sep 04 2020 at 18:55)</a>:</h4>
<p>hmm preferably the scripts shouldn't run while rebasing</p>



<a name="209129171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209129171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209129171">(Sep 04 2020 at 18:55)</a>:</h4>
<p>I came up with a way to do that a while back, one sec</p>



<a name="209130272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209130272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209130272">(Sep 04 2020 at 19:06)</a>:</h4>
<p>here it is:</p>
<div class="codehilite"><pre><span></span><code><span class="c1"># Avoid running hook during rebase</span>
<span class="k">case</span> <span class="s2">&quot;</span><span class="k">$(</span>git branch <span class="p">|</span> grep <span class="s1">&#39;*&#39;</span> <span class="p">|</span> sed <span class="s1">&#39;s/* //&#39;</span><span class="k">)</span><span class="s2">&quot;</span> in
    <span class="s2">&quot;(no branch&quot;</span>*<span class="o">)</span> <span class="nb">exit</span> <span class="m">0</span><span class="p">;;</span>
<span class="k">esac</span>
</code></pre></div>



<a name="209130297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209130297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209130297">(Sep 04 2020 at 19:06)</a>:</h4>
<p>... this is more hacky than I remember <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="209135695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209135695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cass <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209135695">(Sep 04 2020 at 20:05)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/242791-t-infra/topic/git.20hooks/near/209130297">said</a>:</p>
<blockquote>
<p>... this is more hacky than I remember <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>
</blockquote>
<p><span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span> git hooks are like that lol. thanks for the tips! PR incoming shortly <span aria-label="heart" class="emoji emoji-2764" role="img" title="heart">:heart:</span></p>



<a name="209137016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209137016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cass <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209137016">(Sep 04 2020 at 20:22)</a>:</h4>
<p>Ok, so I'm up to speed with <code>tidy</code> running <code>fmt --check</code>. I personally think if we're building this as a convenience feature, it makes sense to have it actually run the formatter and save the changes before running tidy to check things. Would y'all be opposed to running <code>fmt</code> and then <code>tidy</code>? Does <code>tidy --bless</code> act the same as e.g. <code>eslint --fix</code>?</p>



<a name="209137099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209137099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209137099">(Sep 04 2020 at 20:22)</a>:</h4>
<p>tidy --bless will call fmt --bless internally</p>



<a name="209137271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209137271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209137271">(Sep 04 2020 at 20:24)</a>:</h4>
<p>I didn't know that :D thank you!</p>



<a name="209138439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209138439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cass <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209138439">(Sep 04 2020 at 20:38)</a>:</h4>
<p>right -- it's my understanding that <code>--bless</code> means "expect changed test output". I suppose what I'm looking for is some kind of flag that will format as much as possible, and if there's unfixable errors it'll error. After adding some extra indentation to a file and running <code>./x.py test tidy --bless</code> it seems to have automatically fixed the formatting, I just wanted to double check it won't also accidentally, say, pass a test that's supposed to fail</p>



<a name="209138465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209138465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209138465">(Sep 04 2020 at 20:38)</a>:</h4>
<p>if it changes anything, it will show up as part of the commit</p>



<a name="209138473"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209138473" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209138473">(Sep 04 2020 at 20:38)</a>:</h4>
<p>so it should ideally be caught in review</p>



<a name="209138481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209138481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209138481">(Sep 04 2020 at 20:38)</a>:</h4>
<p>but it won't change UI tests or anything so I wouldn't be too worried</p>



<a name="209138498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209138498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cass <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209138498">(Sep 04 2020 at 20:39)</a>:</h4>
<p>Oops! It's in the docs lol:</p>
<blockquote>
<p>Example: ./x.py test tidy --bless does formatting before doing other tidy checks.</p>
</blockquote>
<p>Gotcha. Ok so I'll go ahead with making the pre-commit script call <code>tidy --bless</code></p>



<a name="209154057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242791-t-infra/topic/git%20hooks/near/209154057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cass <a href="https://rust-lang.github.io/zulip_archive/stream/242791-t-infra/topic/git.20hooks.html#209154057">(Sep 05 2020 at 01:05)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/76356">https://github.com/rust-lang/rust/pull/76356</a> ok first draft is up!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>